package com.admin.rxandroidtest;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by 吴昶 on 2018/8/15.
 * 原始写法 已被取代
 */
public class RetrofitTest {

    private String url="https://guangdiu.com/";

//    public void getData(){
//        Retrofit b=new Retrofit.Builder().baseUrl(url).build();
//        ConnectionService service=b.create(ConnectionService.class);
//        Call<ResponseBody> call=service.getBlog();
//        call.enqueue(new Callback<ResponseBody>() {
//            @Override
//            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
//                try {
//                    System.out.println("*****     "+response.body().string());
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//            }
//
//            @Override
//            public void onFailure(Call<ResponseBody> call, Throwable t) {
//
//            }
//        });
//    }

    public void getDataGson(){
        Retrofit b=new Retrofit.Builder()
                .baseUrl(url)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        ConnectionService service=b.create(ConnectionService.class);
        Call<Result> call=service.getBlogGson();
        call.enqueue(new Callback<Result>() {
            @Override
            public void onResponse(Call<Result> call, Response<Result> response) {
                    System.out.println("***** getDataGson **-*    "+response.body());
                    Result result=response.body();
                    System.out.println("--------------------------");
                    if(result==null){
                        System.out.println("result is null");
                    }else {
                        System.out.println(result.getStatus());
                    }
//                System.out.println("   end    ");
            }

            @Override
            public void onFailure(Call<Result> call, Throwable t) {

            }
        });
    }
}
